package com.ymttest.database.sqlwapper.fqlorder;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.fqlorder.FqlOrderInfo;

public class FqlOrderInfoWrapper {
	
	SqlManager manager;

	public FqlOrderInfoWrapper() {
		manager = new SqlManager("fqlordersync");
	}

	@SuppressWarnings("unchecked")
	public FqlOrderInfo selectByPrimaryKey(String id) {

		FqlOrderInfo fqlOrderInfo = new FqlOrderInfo();
		List<FqlOrderInfo> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.fqlorder.FqlOrderInfoMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			fqlOrderInfo = result.get(0);
		}

		return fqlOrderInfo;
	}
	
	/**
	 * 
	 * @param thirdSkuId
	 * @param amount
	 * @param skuNum
	 * @param skuId
	 * @return
	 */
	public int insert(String fql_order_id, String thirdSkuId,
			BigDecimal amount, int skuNum, String skuId) {

		FqlOrderInfo fqlOrderInfo = new FqlOrderInfo();

		fqlOrderInfo.setFql_order_id(fql_order_id);
		fqlOrderInfo.setThird_sku_id(thirdSkuId);
		fqlOrderInfo.setAmount(amount);
		fqlOrderInfo.setSku_num(skuNum);
		fqlOrderInfo.setSku_id(skuId);

		// fqlOrderInfo.setFql_order_id(TestDataManager.randomStr(13));

		fqlOrderInfo.setBuyer_memo("autotest分期乐下单");

		fqlOrderInfo.setReceiver_mobile("18511111111");
		fqlOrderInfo.setReceiver_name("测试");
		fqlOrderInfo.setReceiver_address("上海市洋码头");

		fqlOrderInfo.setAdd_time(new Date());
		fqlOrderInfo.setUpdate_time(new Date());

		int result = manager
				.insert("com.ymttest.database.mapping.fqlorder.FqlOrderInfoMapper.insert",
						fqlOrderInfo);

		manager.commit();

		return result;
	}
	
	public static void main(String[] args) {
		
		FqlOrderInfoWrapper wrapper = new FqlOrderInfoWrapper();
		
//		FqlOrderInfo fqlOrderInfo = new FqlOrderInfo();
//		
//		fqlOrderInfo.setThird_sku_id("c5234");
//		fqlOrderInfo.setAmount(new BigDecimal("1000"));
//		fqlOrderInfo.setSku_num(1);
//		fqlOrderInfo.setSku_id("c123");
//		
//		wrapper.insert(fqlOrderInfo);
		
		System.out.println(wrapper.selectByPrimaryKey("1").getBuyer_id_number());
	}
}
